# encoding: utf-8
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
	has_many :monitoring_files
	
	has_and_belongs_to_many :projects, join_table: :user_projects
  
  validates :email, uniqueness: true
  
  ROLES = {
    :owner => "owner",
    :admin => "admin",
    :viewer => "viewer"
  }
  
  MAX_PROJECTS = {
    "basic" => 2,
    "pro" => 5,
    "premium" => 10
  }

  def project_role(project_id)
    # user's role for the project
    UserProject.where(["project_id = ? and user_id = ?", project_id, self.id]).first.role
  end
end
